package com.mycompany.inventory.pojo;

import java.sql.Date;
import java.util.ArrayList;
import java.util.List;

import org.zkoss.bind.annotation.DependsOn;

public class Product {

	private String Id;
	private String name;
	private Type type;
	private ProductCategories category;
	private String description;
	private String remark;
	private String image;
	private SaleInfo saleinfo = new SaleInfo();
	private List<SaleInfo> saleinfos = new ArrayList<SaleInfo>();
	private ProductInventory inventory = new ProductInventory();
	private List<ProductInventory> inventories = new ArrayList<ProductInventory>();
	private CostingInfo costingInfo;
	private String cost;
	private List<CustomInfo> customs = new ArrayList<CustomInfo>();
	private String code;
	private String cat;
	private boolean deleted;
	private StorageInfo storage = new StorageInfo();
	private String storageInfoId;
	private Inventory location;
	private Vendor vendor;
	private Unit standardUoM;
	private Unit saleUoM;
	private Unit purchaseUoM;
	private String quantity;
	private int normalPrice;
	private String lastVendor;
	private MediaDTO media;
	private String vendorProductCode;
	private String discount;
	private double subTotal;
	private int quantityReceived;
	private int quantityReturn;
	private int quantityUnstock;
	private Date received_date;
	private String receive_status;
	private int onOrder;
	private double subTotalPayment;
	private double subTotalReturn;
	
	public Product() {
		
	}	
	
	public Product(String id, String name, Type type, String description, String remark, MediaDTO media, List<SaleInfo> saleinfos
			, List<ProductInventory> inventories, ProductCategories category, CostingInfo costInfo, String cost, String storageInfoId, Inventory location, Vendor vendor, Unit standardUoM, Unit saleUoM, Unit purchaseUoM, List<CustomInfo> customs) {		
		this.Id = id;
		this.name = name;
		this.type = type;
		this.description = description;
		this.remark = remark;
		this.media = media;
		this.saleinfos = saleinfos;
		this.inventories = inventories;
		this.category = category;
		this.costingInfo = costInfo;
		this.cost = cost;
		this.storageInfoId = storageInfoId;
		this.location = location;
		this.vendor = vendor;
		this.standardUoM = standardUoM;
		this.saleUoM = saleUoM;
		this.purchaseUoM = purchaseUoM;
		this.customs = customs;
	}
	
	public Product(String id, String name, String description, String cost, String quantity) {		
		Id = id;
		this.name = name;
		this.description = description;
		this.cost = cost;
		this.quantity = quantity;
	}
	
	public Product(String id, String name, String description, String vendorProductCode, String quantity, String cost, String discount){
		this.Id = id;
		this.name = name;
		this.description = description;
		this.vendorProductCode = vendorProductCode;
		this.quantity = quantity;
		this.cost = cost;
		this.discount = discount;
	}

	public Product(String id, String name, String description, String vendorProductCode, String quantity, Inventory location, Date receiveDate, String receiveStatus, int onOrder){
		this.Id = id;
		this.name = name;
		this.description = description;
		this.vendorProductCode = vendorProductCode;
		this.quantity = quantity;
		this.location = location;
		this.received_date = receiveDate;
		this.receive_status = receiveStatus;
		this.onOrder = onOrder;
	}
	
	public Product(String id, String name, String description, int quantity, Inventory location, String receiveStatus){
		this.Id = id;
		this.name = name;
		this.description = description;
		this.quantityUnstock = quantity;
		this.location = location;
		this.receive_status = receiveStatus;
	}		
	
	public Product(String id, String remark, StorageInfo storageInfo, Inventory location, Vendor vendor, Unit standardUoM, Unit saleUoM, Unit purchaseUoM){
		this.Id = id;
		this.remark = remark;
		this.storage = storageInfo;
		this.location = location;
		this.vendor = vendor;
		this.standardUoM = standardUoM;
		this.saleUoM = saleUoM;
		this.purchaseUoM = purchaseUoM;
	}
	
	public Product(String id, String name, String cat, String description,
			String code, String cost) {		
		Id = id;
		this.name = name;
		this.cat = cat;
		this.description = description;
		this.code = code;
		this.cost = cost;
		this.deleted = false;
	}	
	
	public void clear(){
		this.Id = "";
		this.name = "";
		this.type = null;
		this.description = "";
		this.remark = "";
		this.image = "";
		this.saleinfos = null;
		this.inventories = null;
		this.category = null;
		this.costingInfo = null;
		this.location = null;
		this.vendor = null;
		this.standardUoM = null;
		this.saleUoM = null;
		this.purchaseUoM = null;
		this.cost = "";
		this.deleted = false;
	}	
	
	public void copyValue(Product product){
		this.Id = product.getId();
		this.name = product.getName();
		this.code = product.getCode();
		this.cat = product.getCat();
		this.cost = product.getCost();
		this.description = product.getDescription();
		this.deleted = product.isDeleted();
	}
	
	public void copyMaterialValue(Product product){
		this.Id = product.getId();
		this.name = product.getName();
		this.description = product.getDescription();
		this.quantity = product.getQuantity();
		this.cost = product.getCost();
	}

	public void copyPurchaseValue(Product product){
		this.Id = product.getId();
		this.name = product.getName();
		this.description = product.getDescription();
		this.vendorProductCode = product.getVendorProductCode();
		this.quantity = product.getQuantity();
		this.cost = product.getCost();
		this.discount = "0";
	}	

	public void copyReceiveProduct(Product product){
		this.Id = product.getId();
		this.name = product.getName();
		this.description = product.getDescription();
		this.vendorProductCode = product.getVendorProductCode();
		this.quantityReceived = product.getQuantityReceived();
		this.location = product.getLocation();
		this.received_date = product.getReceivedDate();
		this.receive_status = product.getReceiveStatus();
		this.onOrder = product.getOnOrder();
	}	

	public void copyReturnProduct(Product product){
		this.Id = product.getId();
		this.name = product.getName();
		this.description = product.getDescription();
		this.vendorProductCode = product.getVendorProductCode();
		this.quantityReturn = product.getQuantityReturn();
		this.cost = product.getCost();
		this.onOrder = product.getOnOrder();
	}	
	
	/**
	 * @return the code
	 */
	public String getCode() {
		return code;
	}

	/**
	 * @param code the code to set
	 */
	public void setCode(String code) {
		this.code = code;
	}

	/**
	 * @return the cat
	 */
	public String getCat() {
		return cat;
	}

	/**
	 * @param cat the cat to set
	 */
	public void setCat(String cat) {
		this.cat = cat;
	}

	/**
	 * @return the id
	 */
	public String getId() {
		return Id;
	}

	/**
	 * @param id the id to set
	 */
	public void setId(String id) {
		Id = id;
	}

	/**
	 * @return the name
	 */
	public String getName() {
		return name;
	}

	/**
	 * @param name the name to set
	 */
	public void setName(String name) {
		this.name = name;
	}

	/**
	 * @return the type
	 */
	public Type getType() {
		return type;
	}

	/**
	 * @param type the type to set
	 */
	public void setType(Type type) {
		this.type = type;
	}
	
	/**
	 * @return the standardUoM
	 */
	public Unit getStandardUoM() {
		return standardUoM;
	}

	/**
	 * @param standardUoM the standardUoM to set
	 */
	public void setStandardUoM(Unit standardUoM) {
		this.standardUoM = standardUoM;
	}

	/**
	 * @return the saleUoM
	 */
	public Unit getSaleUoM() {
		return saleUoM;
	}

	/**
	 * @param saleUoM the saleUoM to set
	 */
	public void setSaleUoM(Unit saleUoM) {
		this.saleUoM = saleUoM;
	}

	/**
	 * @return the purchaseUoM
	 */
	public Unit getPurchaseUoM() {
		return purchaseUoM;
	}

	/**
	 * @param purchaseUoM the purchaseUoM to set
	 */
	public void setPurchaseUoM(Unit purchaseUoM) {
		this.purchaseUoM = purchaseUoM;
	}

	/**
	 * @return the category
	 */
	public ProductCategories getCategory() {
		return category;
	}

	/**
	 * @param category the category to set
	 */
	public void setCategory(ProductCategories category) {
		this.category = category;
	}

	/**
	 * @return the description
	 */
	public String getDescription() {
		return description;
	}

	/**
	 * @param description the description to set
	 */
	public void setDescription(String description) {
		this.description = description;
	}

	/**
	 * @return the remark
	 */
	public String getRemark() {
		return remark;
	}

	/**
	 * @param remark the remark to set
	 */
	public void setRemark(String remark) {
		this.remark = remark;
	}

	/**
	 * @return the image
	 */
	public String getImage() {
		return image;
	}

	/**
	 * @param image the image to set
	 */
	public void setImage(String image) {
		this.image = image;
	}

	/**
	 * @return the saleinfo
	 */
	public SaleInfo getSaleinfo() {
		return saleinfo;
	}

	/**
	 * @param saleinfo the saleinfo to set
	 */
	public void setSaleinfo(SaleInfo saleinfo) {
		this.saleinfo = saleinfo;
	}

	/**
	 * @return the saleinfos
	 */
	public List<SaleInfo> getSaleinfos() {
		return saleinfos;
	}

	/**
	 * @param saleinfos the saleinfos to set
	 */
	public void setSaleinfos(List<SaleInfo> saleinfos) {
		this.saleinfos = saleinfos;
	}

	/**
	 * @return the inventory
	 */
	public ProductInventory getInventory() {
		return inventory;
	}

	/**
	 * @param inventory the inventory to set
	 */
	public void setInventory(ProductInventory inventory) {
		this.inventory = inventory;
	}

	/**
	 * @return the inventories
	 */
	public List<ProductInventory> getInventories() {
		return inventories;
	}

	/**
	 * @param inventories the inventories to set
	 */
	public void setInventories(List<ProductInventory> inventories) {
		this.inventories = inventories;
	}

	/**
	 * @return the costingInfo
	 */
	public CostingInfo getCostingInfo() {
		return costingInfo;
	}

	/**
	 * @param costingInfo the costingInfo to set
	 */
	public void setCostingInfo(CostingInfo costingInfo) {
		this.costingInfo = costingInfo;
	}

	/**
	 * @return the cost
	 */
	public String getCost() {
		return cost;
	}

	/**
	 * @param cost the cost to set
	 */
	public void setCost(String cost) {
		this.cost = cost;
	}

	public List<CustomInfo> getCustoms() {
		return customs;
	}

	public void setCustoms(List<CustomInfo> customs) {
		this.customs = customs;
	}	
	
	public boolean isDeleted() {
		return deleted;
	}

	public void setDeleted(boolean deleted) {
		this.deleted = deleted;
	}

	public StorageInfo getStorage() {
		return storage;
	}

	public void setStorage(StorageInfo storage) {
		this.storage = storage;
	}

	public String getStorageInfoId() {
		return storageInfoId;
	}

	public void setStorageInfoId(String storageInfoId) {
		this.storageInfoId = storageInfoId;
	}

	/**
	 * @return the location
	 */
	public Inventory getLocation() {
		return location;
	}

	/**
	 * @param location the location to set
	 */
	public void setLocation(Inventory location) {
		this.location = location;
	}

	/**
	 * @return the vendor
	 */
	public Vendor getVendor() {
		return vendor;
	}

	/**
	 * @param vendor the vendor to set
	 */
	public void setVendor(Vendor vendor) {
		this.vendor = vendor;
	}

	/**
	 * @return the quantity
	 */
	public String getQuantity() {
		return quantity;
	}

	/**
	 * @param quantity the quantity to set
	 */
	public void setQuantity(String quantity) {
		this.quantity = quantity;
	}

	/**
	 * @return the normalPrice
	 */
	public int getNormalPrice() {
		return normalPrice;
	}

	/**
	 * @param normalPrice the normalPrice to set
	 */
	public void setNormalPrice(int normalPrice) {
		this.normalPrice = normalPrice;
	}

	/**
	 * @return the lastVendor
	 */
	public String getLastVendor() {
		return lastVendor;
	}

	/**
	 * @param lastVendor the lastVendor to set
	 */
	public void setLastVendor(String lastVendor) {
		this.lastVendor = lastVendor;
	}

	/**
	 * @return the media
	 */
	public MediaDTO getMedia() {
		return media;
	}

	/**
	 * @param media the media to set
	 */
	public void setMedia(MediaDTO media) {
		this.media = media;
	}

	/**
	 * @return the vendorProductCode
	 */
	public String getVendorProductCode() {
		return vendorProductCode;
	}

	/**
	 * @param vendorProductCode the vendorProductCode to set
	 */
	public void setVendorProductCode(String vendorProductCode) {
		this.vendorProductCode = vendorProductCode;
	}

	/**
	 * @return the discount
	 */
	public String getDiscount() {
		return discount;
	}

	/**
	 * @param discount the discount to set
	 */
	public void setDiscount(String discount) {
		this.discount = discount;
	}

	/**
	 * @return the subTotal
	 */
	@DependsOn({"discount","cost","quantity"})
	public double getSubTotal() {
		if(discount.equals("") || discount.equals("0"))
			discount = "100";
		if(cost.equals(""))
			cost = "0";
		if(quantity.equals(""))
			quantity = "0";
		return subTotal =Double.parseDouble(cost)*Integer.parseInt(quantity) - ((Double.parseDouble(discount)/100)*Double.parseDouble(cost)*Integer.parseInt(quantity));
	}

	/**
	 * @param subTotal the subTotal to set
	 */
	public void setSubTotal(double subTotal) {
		this.subTotal = subTotal;
	}

	/**
	 * @return the quantity_received
	 */
	public int getQuantityReceived() {
		return quantityReceived;
	}

	/**
	 * @param quantity_received the quantity_received to set
	 */
	public void setQuantityReceived(int quantityReceived) {
		this.quantityReceived = quantityReceived;
	}

	/**
	 * @return the received_date
	 */
	public Date getReceivedDate() {
		return received_date;
	}

	/**
	 * @param received_date the received_date to set
	 */
	public void setReceivedDate(Date received_date) {
		this.received_date = received_date;
	}

	/**
	 * @return the receive_status
	 */
	public String getReceiveStatus() {
		return receive_status;
	}

	/**
	 * @param receive_status the receive_status to set
	 */
	public void setReceiveStatus(String receive_status) {
		this.receive_status = receive_status;
	}

	/**
	 * @return the onOrder
	 */
	public int getOnOrder() {
		return onOrder;
	}

	/**
	 * @param onOrder the onOrder to set
	 */
	public void setOnOrder(int onOrder) {
		this.onOrder = onOrder;
	}

	/**
	 * @return the received_date
	 */
	public Date getReceived_date() {
		return received_date;
	}

	/**
	 * @param received_date the received_date to set
	 */
	public void setReceived_date(Date received_date) {
		this.received_date = received_date;
	}

	/**
	 * @return the receive_status
	 */
	public String getReceive_status() {
		return receive_status;
	}

	/**
	 * @param receive_status the receive_status to set
	 */
	public void setReceive_status(String receive_status) {
		this.receive_status = receive_status;
	}

	/**
	 * @return the subTotalPayment
	 */
	public double getSubTotalPayment() {
		return subTotalPayment;
	}

	/**
	 * @param subTotalPayment the subTotalPayment to set
	 */
	public void setSubTotalPayment(double subTotalPayment) {
		this.subTotalPayment = subTotalPayment;
	}

	/**
	 * @return the subTotalReturn
	 */
	@DependsOn({"cost","quantityReturn"})	
	public double getSubTotalReturn() {
		if(cost.equals(""))
			cost = "0";
		return subTotalReturn =Double.parseDouble(cost)*quantityReturn;		
	}

	/**
	 * @param subTotalReturn the subTotalReturn to set
	 */
	public void setSubTotalReturn(double subTotalReturn) {
		this.subTotalReturn = subTotalReturn;
	}

	/**
	 * @return the quantityReturn
	 */
	public int getQuantityReturn() {
		return quantityReturn;
	}

	/**
	 * @param quantityReturn the quantityReturn to set
	 */
	public void setQuantityReturn(int quantityReturn) {
		this.quantityReturn = quantityReturn;
	}

	/**
	 * @return the quantityUnstock
	 */
	public int getQuantityUnstock() {
		return quantityUnstock;
	}

	/**
	 * @param quantityUnstock the quantityUnstock to set
	 */
	public void setQuantityUnstock(int quantityUnstock) {
		this.quantityUnstock = quantityUnstock;
	}
	
}
